package com.boolib.http.core.util;

/**
 * @author nier
 */
public class ClassNameUtil {

    private static final String split = ".";

    /**
     * 首字母转小写
     *
     * @param s
     * @return
     */
    public static String toLowerCaseFirstOne(String s) {
        if (Character.isLowerCase(s.charAt(0))) {
            return s;
        } else {
            return (new StringBuilder()).append(Character.toLowerCase(s.charAt(0))).append(s.substring(1)).toString();
        }
    }

    /**
     * 首字母转大写
     *
     * @param s
     * @return
     */
    public static String toUpperCaseFirstOne(String s) {
        if (Character.isUpperCase(s.charAt(0))) {
            return s;
        } else {
            return (new StringBuilder()).append(Character.toUpperCase(s.charAt(0))).append(s.substring(1)).toString();
        }
    }


    /**
     * 获取最后名称
     *
     * @param s
     * @return
     */
    public static String getLastName(String s) {

        if (split.contains(s)) {
            int i = s.lastIndexOf(split);

            String substring = s.substring(i + 1, s.length());

            return substring;
        }
        return s;

    }


    /**
     * 通过完全限定名获取bean的名称
     *
     * @param name
     * @return
     */
    public static String getBeanName(String name) {
        return toLowerCaseFirstOne(getLastName(name));
    }
}
